package ai.people.platform.archives.service.impl;

import ai.people.core.security.entity.AuthenticationUser;
import ai.people.core.security.support.RequestHolderUtil;
import ai.people.netmon.framework.domain.archives.entity.PersonArchivesEdges;
import ai.people.netmon.framework.domain.archives.vo.ArchivesEdgesVO;
import ai.people.netmon.framework.exception.enums.CommonEnum;
import ai.people.netmon.framework.utils.AssertUtils;
import ai.people.platform.archives.mapper.PersonArchivesEdgesMapper;
import ai.people.platform.archives.service.PersonArchivesEdgesService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhenglin
 * @since 2022-04-26
 */
@Service
public class PersonArchivesEdgesServiceImpl extends ServiceImpl<PersonArchivesEdgesMapper, PersonArchivesEdges> implements PersonArchivesEdgesService {

    @Autowired
    PersonArchivesEdgesMapper mapper;

    @Override
    public List<ArchivesEdgesVO> listEdges() {
       return mapper.listEdgesVO();
    }

    @Override
    public void addEdge(PersonArchivesEdges edge) {
        //获取登录用户ID
        AuthenticationUser loginUser = RequestHolderUtil.loginUser();
        Long userId = loginUser.getUserId();
        edge.setCreatorId(userId);
        boolean save = save(edge);
        AssertUtils.isTrue(save, CommonEnum.FAIL);
    }
}
